import json

import requests

# https://tieba.baidu.com/f?kw=%E9%92%93%E9%B1%BC&pn=0&    pn以50为倍数下一页

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36',
    'Cookie': 'BAIDUID=55425EE6DD6A8C0204BA217145FDE96B:FG=1; USER_JUMP=-1; tb_as_data=865b99f7fc73ac140eb948797c7d14a27591773988d7102358976f1f77c31f28af416f7bd37600b2bde2d164ab7a2a893565551b4d7cb7377c0288b10bf6d688531ff946e1dec95d4b30cd10f2f797d2; SEENKW=%E9%92%93%E9%B1%BC; mo_originid=2; IS_NEW_USER=b945a2da0e829abed6fe144f; BAIDU_WISE_UID=wapp_1604409888394_766; CLIENTWIDTH=823; CLIENTHEIGHT=888; LASW=823; st_data=c8b4956885495c1f09b463675ea8d389ad640e50d825fcd946b0ed61c357b4e6dae3f1fa13ea8ad9ee99c6c4ea7d6f870f15070c659cdc953faf6aaae0bd68eb04e57ff243b76a4e05be3ed2bae24cc8826d3f2b21d06b2c59dc7fbddd93441ad27d9432d50897d1b641389d0672f7e50333a6c529778d60fee1034bbc2351c0; st_key_id=17; st_sign=2db3609f'
}

params = {
    'kw': '钓鱼',
    'pn': '0',
    'ie':'utf-8'
}

# r = requests.get(url=url, headers=headers,params=params)
list = [0, 50, 100]
data_list =[]
for x in list:
    url = 'https://tieba.baidu.com/f?kw=%E9%92%93%E9%B1%BC&pn={}'.format(x)
    r = requests.get(url=url, headers=headers)
    r.encoding = 'utf-8'
    open_path = 'pnn{}.txt'.format(x)
    with open(open_path, 'w',encoding='utf-8') as b:
        b.write(r.text)
        print(type(r.text))
        # data_list.append(str(r.text))
    # print(r.text)
    print(r.url)
    # print(data_list[0])

